var current_conditions = ""; //当前查询品牌条件
var whether_only_on_sale = false; //是否仅在售
var all_conditions = []; //依次保存全部条件的json对象{conditions_type,conditions_name,conditions}
var car_series_count = 0; //历史浏览/我的关注 车系数量
var pages = 0; //总页数
var pageIndex = 1; //当前页数
var load_leng = 1800; //指定高度加载一次
var all_parameters = ""; //全部参数  x-x-x-x-x-x-x-1
var all_parameters_array = {}; //条件数组
var brand_name = ""; //品牌名称
var price = ""; //价格
var level = ""; //级别
var car_points = ""; //懂车分
var energy = ""; //能源
var different_countries = ""; //国别
var seat_num = ""; //座位数

$(document).ready(function() {
	get_user_mess_and_token();
	var url = location.search;
	all_parameters = url.substr(1);
	if (all_parameters != "") {
		all_parameters_array = all_parameters.split("-");
		brand_name = all_parameters_array[0].split(",")[1];
	}
	if (all_parameters != null && all_parameters.trim().length != 0) {
		/* 修改登录url */
		$(".to_login").attr("href",
			"http://127.0.0.1:8899/html/car_login.html?car_vehicle_selection/" +
			all_parameters);
	}
	$(".series-collection_link__3i4Im").attr("href",
		"http://127.0.0.1:8899/html/car_my_follow.html?" + user_id); //查看全部车系
	if (token != "") { //已登录
		$("#prompt_for_login").hide();
	}
	/* 加载全部数据 */
	load_all_vehicle_selection_data();
});

/* 加载全部数据 */
function load_all_vehicle_selection_data() {
	$.post("http://127.0.0.1:8899/api/consumer/PublicController/load_all_vehicle_selection_data", function(data) {
		/* 加载热门品牌 */
		load_popularity_brand('popularity');

		/* 加载全部级别 */
		var all_car_level_data = "";
		$(data.all_car_level).each(function(index, item) {
			if (item.car_level_id == all_parameters_array[2]) {
				level = item.car_level_name;
				$("#all_car_level a").attr("class", "filters_item__3FqtJ");
			}
			all_car_level_data +=
				"<a class=\"" + (item.car_level_id == all_parameters_array[2] ?
					"filters_item__3FqtJ filters_selected__2JJnq" : "filters_item__3FqtJ") +
				"\" onclick=\"add_select_conditions('level'," + item
				.car_level_id + ",'" + item.car_level_name + "',this);\" href=\"javascript:void(0)\">" +
				item
				.car_level_name + "</a>";
		});
		$("#all_car_level").append(all_car_level_data);

		/* 加载全部能源 */
		var all_energy_data = "";
		$(data.all_energy).each(function(index, item) {
			if (item.energy_id == all_parameters_array[4]) {
				energy = item.energy_name;
				$("#all_energy a").attr("class", "filters_item__3FqtJ");
			}
			all_energy_data +=
				"<a class=\"" + (item.energy_id == all_parameters_array[4] ?
					"filters_item__3FqtJ filters_selected__2JJnq" : "filters_item__3FqtJ") +
				"\" onclick=\"add_select_conditions('energy'," + item
				.energy_id + ",'" + item.energy_name + "',this);\" href=\"javascript:void(0)\">" + item
				.energy_name +
				"</a>";
		});
		$("#all_energy").append(all_energy_data);

		/* 加载全部国别 */
		var all_different_countries_data = "";
		$(data.all_different_countries).each(function(index, item) {
			if (item.different_countries_id == all_parameters_array[5]) {
				different_countries = item.different_countries_name;
				$("#all_different_countries a").attr("class", "filters_item__3FqtJ");
			}
			all_different_countries_data +=
				"<a class=\"" + (item.different_countries_id == all_parameters_array[5] ?
					"filters_item__3FqtJ filters_selected__2JJnq" : "filters_item__3FqtJ") +
				"\" onclick=\"add_select_conditions('different_countries'," +
				item.different_countries_id + ",'" + item.different_countries_name +
				"',this);\" href=\"javascript:void(0)\" rel=\"opener\">" + item
				.different_countries_name + "</a>";
		});
		$("#all_different_countries").append(all_different_countries_data);

		/* 查询历史浏览车系 */
		select_history_browsing_car_series();

		if (all_parameters != "") {
			for (var index in all_parameters_array) {
				var conditions_type = "";
				var conditions_name = "";
				if (index == 0 && all_parameters_array[0] != "x") {
					brand_name = decodeURI(all_parameters_array[0].split(",")[1]);
					conditions_name = brand_name;
					conditions_type = "brand";
				} else if (index == 1 && all_parameters_array[1] != "x") {
					$("#layout_content__hziOT a").attr("filters_item__3FqtJ"); //filters_selected__2JJnq
					price = all_parameters_array[1].indexOf("+") != -1 ? all_parameters_array[1].split(",")[0] +
						"万以上" : all_parameters_array[1].replace(",", "-") + "万";
					conditions_name = price;
					conditions_type = "price";
					if (all_parameters_array[1] == "0,10") {
						$("#layout_content__hziOT a:eq(1)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[1] == "10,15") {
						$("#layout_content__hziOT a:eq(2)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[1] == "15,20") {
						$("#layout_content__hziOT a:eq(3)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[1] == "20,25") {
						$("#layout_content__hziOT a:eq(4)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[1] == "25,30") {
						$("#layout_content__hziOT a:eq(5)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[1] == "30,40") {
						$("#layout_content__hziOT a:eq(6)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[1] == "50,+") {
						$("#layout_content__hziOT a:eq(7)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[1] == "100,+") {
						$("#layout_content__hziOT a:eq(8)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					}
				} else if (index == 2 && all_parameters_array[2] != "x") {
					conditions_name = level;
					conditions_type = "level";
				} else if (index == 3 && all_parameters_array[3] != "x") {
					car_points = all_parameters_array[3].replace(",", "-") + "分";
					conditions_name = car_points;
					conditions_type = "points";
					if (all_parameters_array[3] == "0,3") {
						$("#all_points a:eq(1)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[3] == "3.0,3.5") {
						$("#all_points a:eq(2)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[3] == "3.5,4.0") {
						$("#all_points a:eq(3)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[3] == "4.0,4.5") {
						$("#all_points a:eq(4)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[3] == "4.5,5.0") {
						$("#all_points a:eq(5)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					}
				} else if (index == 4 && all_parameters_array[4] != "x") {
					conditions_name = energy;
					conditions_type = "energy";
				} else if (index == 5 && all_parameters_array[5] != "x") {
					conditions_name = different_countries;
					conditions_type = "different_countries";
				} else if (index == 6 && all_parameters_array[6] != "x") {
					seat_num = all_parameters_array[6].indexOf("+") != -1 ? "7座以上" : all_parameters_array[6] +
						"座";
					conditions_name = seat_num;
					conditions_type = "seat_num";
					if (all_parameters_array[6] == "2") {
						$("#all_seat_num a:eq(1)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[6] == "4") {
						$("#all_seat_num a:eq(2)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[6] == "5") {
						$("#all_seat_num a:eq(3)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[6] == "6") {
						$("#all_seat_num a:eq(4)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[6] == "7") {
						$("#all_seat_num a:eq(5)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					} else if (all_parameters_array[6] == "7+") {
						$("#all_seat_num a:eq(6)").attr("class",
							"filters_item__3FqtJ filters_selected__2JJnq").siblings("a").attr("class",
							"filters_item__3FqtJ");
					}
				}
				if (all_parameters_array[index] != "x") {
					all_conditions[index] = JSON.parse("{\"conditions_type\":\"" + conditions_type +
						"\",\"conditions_name\":\"" +
						conditions_name + "\",\"conditions\":\"" + (index == 0 ? all_parameters_array[index]
							.split(",")[0] : all_parameters_array[index]) + "\"}");
				}
			}
			flush_selected_conditions();
			splicing_conditions_url();
		} else {
			/* 默认无条件查询30个车系 */
			select_all_series_by_conditions("x-x-x-x-x-x-x-1");
		}
	}, "json");
}

/* 加载热门品牌/根据指定字母查询品牌 */
function load_popularity_brand(conditions) {
	current_conditions = conditions; /* 保存当前条件 */
	/* 加载热门品牌--20个/根据指定字母查询品牌 */
	var all_popularity_brand_data = "";
	$.post("http://127.0.0.1:8899/api/consumer/BrandController/select_popularity_brand/" + conditions + "/" +
		whether_only_on_sale,
		function(data) {
			$(data).each(function(index, item) {
				all_popularity_brand_data +=
					"<li class=\"brand_brand__2q2X1\">" +
					"<a class=\"" + (brand_name == item.brand_name ?
						"brand_link__3F8eK brand_selected__3YcFo" : "brand_link__3F8eK") +
					"\" onclick=\"add_select_conditions('brand'," + item
					.brand_id + ",'" + item.brand_name + "',this);\" href=\"javascript:void(0)\">" +
					"<div style=\"display:inline-block;max-width:100%;overflow:hidden;position:relative;z-index:0\" class=\"brand_image__2yj7_\">" +
					"<div style=\"box-sizing:border-box;display:block;max-width:100%\">" +
					"<img src=\"http://120.48.47.144:8899/images/" + item.brand_images
					.brand_images_car_logo_url +
					"\" width=\"20px\" height=\"20px\" style=\"display:block;margin:0;border:none;padding:0\" />" +
					"</div>" +
					"</div>" +
					"<span class=\"brand_name__1-UUM\" title=\"" + item.brand_name + "\">" + item
					.brand_name + "</span>" +
					"</a>" +
					"</li>";
			});
			$(".brand_brands__1VgjE li").remove();
			$(".brand_brands__1VgjE").append(all_popularity_brand_data);
		}, "json");
}

/* 查询历史浏览车系 */
function select_history_browsing_car_series() {
	$.post("http://127.0.0.1:8899/api/consumer/Car_seriesController/select_history_browsing_car_series", function(
		data) {
		if (data != null) {
			$(".series-collection_link__3i4Im").hide(); //隐藏查看全部车系
			$("#history_browsing").show();
			$("#spilt_line").show();
			$(".follow_empty__2-g7o").hide();
			$("#history_browsing").attr("class",
				"series-collection_type-item__1Bkxj series-collection_active__3-tAO");
			$("#my_follow").attr("class", "series-collection_type-item__1Bkxj");
			if ((car_series_count = data.length) >
				5) { //保存历史浏览车系个数
				$(".series-collection_navigation__vgYGq").show(); /* 显示翻动查看按钮 */
				$(".series-collection_navigation__vgYGq i:eq(1)").attr("onclick", "to_right_show()");
				$(".series-collection_navigation__vgYGq i:eq(1)").attr("class",
					"DCD_Icon icon_into_12 wrapped-swiper_circle__39IYv wrapped-swiper_button__35fg2");
			}
			var history_browsing_car_series_data = "";
			$(data).each(function(index, item) {
				history_browsing_car_series_data += get_car_series_str(item);
			});
			$(".swiper-wrapper div").remove();
			$(".swiper-wrapper").append(history_browsing_car_series_data);
		} else {
			$("#history_browsing").hide();
			$("#spilt_line").hide();
			$(".series-collection_navigation__vgYGq").hide();
			$("#history_browsing").attr("class", "series-collection_type-item__1Bkxj");
			$("#my_follow").attr("class", "series-collection_type-item__1Bkxj series-collection_active__3-tAO");
			switch_history_follow("follow"); //查询我的关注
		}
	}, "json");
}

/* 查询我的关注 */
function select_my_follow() {
	if (token != "") {
		$.post("http://127.0.0.1:8899/api/consumer/Car_seriesController/select_my_follow_car_series/" + token, function(
			data) {
			if (data.result == "no_line") {
				token = "";
				$("#prompt_for_login").show(); //提示登陆
			} else if (data.length == 0) {
				$(".series-collection_link__3i4Im").hide();
				$("#no_follow_car_series").show(); //没有数据
			} else {
				$("#no_follow_car_series").hide();
				$(".series-collection_link__3i4Im").show();
				if ((car_series_count = data.length) > 5) {
					$(".series-collection_navigation__vgYGq").show(); /* 显示翻动查看按钮 */
					$(".series-collection_navigation__vgYGq i:eq(1)").attr("onclick", "to_right_show()");
					$(".series-collection_navigation__vgYGq i:eq(1)").attr("class",
						"DCD_Icon icon_into_12 wrapped-swiper_circle__39IYv wrapped-swiper_button__35fg2");
				}
				var my_follow_car_series_data = "";
				$(data).each(function(index, item) {
					my_follow_car_series_data += get_car_series_str(item);
				});
				$(".swiper-wrapper div").remove();
				$(".swiper-wrapper").append(my_follow_car_series_data);
			}
		}, "json");
	} else {
		$("#prompt_for_login").show();
	}
}

/* 查询历史浏览车系/关注车系字符串 */
function get_car_series_str(item) {
	return "<div class=\"swiper-slide wrapped-swiper_slide__21UNd\" style=\"margin-right: 12px;\">" +
		"<a class=\"series-item_root__Hedy8\" href=\"http://127.0.0.1:8899/html/car_series_index.html?" + item
		.car_series_id + "\" target=\"_blank\" >" +
		"<div class=\"series-item_image__1VHtp\" style=\"display: inline-block; max-width: 100%; overflow: hidden; position: relative; z-index: 0;\">" +
		"<img src=\"http://120.48.47.144:8899/images/" + item.car_series_images_url_1 +
		"\" " +
		"width=\"100\" height=\"70\" style=\"position: absolute; inset: 0px; box-sizing: border-box; padding: 0px; border: none; margin: auto; display: block; width: 0px; height: 0px; min-width: 100%; max-width: 100%; min-height: 100%; max-height: 100%; object-fit: cover;\">" +
		"</div>" +
		"<div class=\"series-item_info__yOyb9\"><strong " +
		"class=\"series-item_name__2juLs\">" + item.car_series_name + "</strong><span " +
		"class=\"series-item_score__1KAve\"><img " +
		"src=\"//lf3-motor.dcarstatic.com/obj/motor-fe-static/motor/pc/_next/./static/images/score-4f6b4186576fc452392c..svg\" " +
		"alt=\"懂车分\" height=\"16\">" +
		"<div class=\"jsx-724439296 series-item_star__Ai4u2 stars_stars-wrapper__zg7gU\" " +
		"style=\"--starWidth:12; --starHeight:12; --marginRight:0; --icon:url(\/\/lf3-motor\.dcarstatic\.com\/obj\/motor-fe-static\/motor\/pc\/_next\/\.\/static\/images\/star-highlight-6092d405945e3a2a3a5f\.\.png); --icon-vacant:url(\/\/lf3-motor\.dcarstatic\.com\/obj\/motor-fe-static\/motor\/pc\/_next\/\.\/static\/images\/star-normal-0d71d2c21de0ccf62fd0\.\.png);\" >" +
		"<span class=\"jsx-724439296 stars_star__2uVtU\"></span><span " +
		"class=\"" + (item.car_points.car_points_avg > 1.5 ?
			"jsx-724439296 stars_star__2uVtU" : "jsx-4248337184 stars_star-vacant__Tfvup") +
		"\"></span><span " +
		"class=\"" + (item.car_points.car_points_avg > 2.5 ?
			"jsx-724439296 stars_star__2uVtU" : "jsx-4248337184 stars_star-vacant__Tfvup") +
		"\"></span><span " +
		"class=\"" + (item.car_points.car_points_avg > 3.5 ?
			"jsx-724439296 stars_star__2uVtU" : "jsx-4248337184 stars_star-vacant__Tfvup") +
		"\"></span><span " +
		"class=\"" + (item.car_points.car_points_avg > 4.5 ?
			"jsx-724439296 stars_star__2uVtU" : "jsx-4248337184 stars_star-vacant__Tfvup") +
		"\" style=\"background-image:https://lf3-motor.dcarstatic.com/obj/motor-fe-static/motor/pc/_next/static/images/star-normal-0d71d2c21de0ccf62fd0..png\"></span>" +
		"</div>" + item.car_points.car_points_avg + "分" +
		"</span><span class=\"series-item_price__2zZfX\">" + item.min_manufacturer_price +
		"-" + item.max_manufacturer_price + "万</span>" +
		"</div>" +
		"</a>" +
		"</div>"
}

/* 添加查询条件 */
function add_select_conditions(conditions_type, conditions, conditions_name, element) {
	/* (条件类别，具体条件，条件名称，当前对象) */
	load_leng = 1800;
	pageIndex = 1;
	$(".car-list_root__3bcdu li").remove(); /* 清空车系/精美车图 */
	if (conditions_type == "brand") {
		/* 添加品牌条件 */
		$(element).parent().parent().find("a").attr("class", "brand_link__3F8eK");
		$(element).attr("class", "brand_link__3F8eK brand_selected__3YcFo"); //选中当前元素
		all_conditions[0] = JSON.parse("{\"conditions_type\":\"" + conditions_type + "\",\"conditions_name\":\"" +
			conditions_name + "\",\"conditions\":\"" + conditions + "\"}");
		/* 品牌找车 */
		if ($("#switch_preferences a:eq(1)").attr("class") ==
			"jsx-2546748851 tw-inline-block tw-text-16 tw-leading-24 tw-text-common-black tw-mr-40 tw-relative xl:tw-text-18 xl:tw-leading-28 tw-font-semibold"
		) {
			$("#brand_mess").css("display", "block");
			/* 查询指定品牌信息 */
			select_brand_mess(conditions);
		}
		splicing_conditions_url();
	} else if (conditions_type == "price") {
		/* 添加价格条件 */
		add_appoint_conditions(element, conditions, conditions_type, conditions_name, 1);
	} else if (conditions_type == "level") {
		/* 添加级别条件 */
		add_appoint_conditions(element, conditions, conditions_type, conditions_name, 2);
	} else if (conditions_type == "points") {
		/* 添加懂车分条件 */
		add_appoint_conditions(element, conditions, conditions_type, conditions_name, 3);
	} else if (conditions_type == "energy") {
		/* 添加能源条件 */
		add_appoint_conditions(element, conditions, conditions_type, conditions_name, 4);
	} else if (conditions_type == "different_countries") {
		/* 添加国别条件 */
		add_appoint_conditions(element, conditions, conditions_type, conditions_name, 5);
	} else if (conditions_type == "seat_num") {
		/* 添加座位数条件 */
		add_appoint_conditions(element, conditions, conditions_type, conditions_name, 6);
	}
	/* 刷新已选条件 */
	flush_selected_conditions();
}

/* 查询品牌信息 */
function select_brand_mess(brand_id) {
	$.post("http://127.0.0.1:8899/api/consumer/BrandController/select_brand_mess_by_id/" + brand_id, function(data) {
		$("#brand_mess div").remove();
		$("#brand_mess").append("<div class=\"introduce_left__2Tpdc\" style=\"width:1650px\"><img " +
			"src=\"http://120.48.47.144:8899/images/" + data.brand_images.brand_images_background_url +
			"\" " +
			"class=\"introduce_background__WqUk6\" draggable=\"false\"> " +
			"<div class=\"introduce_title__1fZVT\"> " +
			"<div class=\"introduce_image__2HznJ\" " +
			"style=\"display: inline-block; max-width: 100%; overflow: hidden; position: relative; z-index: 0;\"> " +
			"<div style=\"box-sizing: border-box; display: block; max-width: 100%;\"><img " +
			"src=\"data:image/svg+xml;utf-8,<svg width=&quot;36&quot; height=&quot;36&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot;/>\" " +
			"aria-hidden=\"true\" role=\"presentation\" " +
			"style=\"max-width: 100%; display: block; margin: 0px; border: none; padding: 0px;\"> " +
			"</div><img " +
			"src=\"http://120.48.47.144:8899/images/" + data.brand_images.brand_image_url + "\" " +
			"width=\"36\" height=\"36\" " +
			"style=\"position: absolute; inset: 0px; box-sizing: border-box; padding: 0px; border: none; margin: auto; display: block; width: 0px; height: 0px; min-width: 100%; max-width: 100%; min-height: 100%; max-height: 100%; object-fit: cover;\"> " +
			"</div> " +
			"<h1 class=\"introduce_name__W2ayn\">" + data.brand_name + "</h1> " +
			"</div> " +
			"<p class=\"introduce_brief__2lTQw\"><span class=\"introduce_item__1Qvda\"><span " +
			"class=\"introduce_label__3Kb52\">中文名称</span><span " +
			"class=\"introduce_text__86uyp\">" + data.brand_name + "</span></span><span " +
			"class=\"introduce_item__1Qvda\"><span " +
			"class=\"introduce_label__3Kb52\">英文名称</span><span " +
			"class=\"introduce_text__86uyp\">" + data.brand_english_name + "</span></span><span " +
			"class=\"introduce_item__1Qvda\"><span " +
			"class=\"introduce_label__3Kb52\">品牌类型</span><span " +
			"class=\"introduce_text__86uyp\">" + data.brand_type_name + "</span></span><span " +
			"class=\"introduce_item__1Qvda\"><span " +
			"class=\"introduce_label__3Kb52\">国别</span><span " +
			"class=\"introduce_text__86uyp\">" + data.different_countries.different_countries_name +
			"</span></span></p> " +
			"<p class=\"introduce_abstract__3gCyb g-cus-scroll-bar\"> " +
			data.brand_brief_introduction + "</p></div>");
	}, "json");
}

/* 添加指定条件 */
function add_appoint_conditions(element, conditions, conditions_type, conditions_name, index) {
	/* (当前元素，具体条件，条件类型，条件名称，条件集合的索引) */
	$(element).siblings("a").attr("class", "filters_item__3FqtJ");
	$(element).attr("class", "filters_item__3FqtJ filters_selected__2JJnq"); //选中当前元素
	if (conditions == "x-x") { //不限：删除原本条件
		all_conditions[index] = null;
	} else {
		all_conditions[index] = JSON.parse("{\"conditions_type\":\"" + conditions_type + "\",\"conditions_name\":\"" +
			conditions_name + "\",\"conditions\":\"" + conditions + "\"}");
	}
	splicing_conditions_url(); /* 修改条件url */
}

/* 刷新已选条件 */
function flush_selected_conditions() {
	/* 清除全部条件 */
	$(".filters_selected-list__3LDyn a").remove();
	/* 循环条件集合，添加已选条件 */
	for (var item in all_conditions) {
		if (all_conditions[item] != null)
			$(".filters_selected-list__3LDyn").append(
				"<a class=\"filters_selected-item__2M9Jk\" onclick=\"delete_conditions(this,'" + all_conditions[item]
				.conditions_type + "');\" href=\"javascript:void(0)\">" + all_conditions[item].conditions_name +
				"<i class=\"DCD_Icon icon_close_24\"></i>");
	}
	/* 判断是否还有条件 */
	if ($(".filters_selected-list__3LDyn a").length != 0) {
		$("#all_conditions").show();
		$("#tw-mt-32_series-collection_root__58y5u").hide();
	} else {
		$("#all_conditions").hide();
		$("#tw-mt-32_series-collection_root__58y5u").show();
	}
}

/* 删除条件 */
function delete_conditions(element, conditions_type) {
	/* (当前元素，条件类型) */
	$(element).remove();
	load_leng = 1800;
	pageIndex = 1;
	$(".car-list_root__3bcdu li").remove(); /* 清空车系/精美车图 */
	if (conditions_type == "brand") {
		/* 品牌条件 */
		all_conditions[0] = null;
		brand_name = "";
		$(".brand_brands__1VgjE a").attr("class", "brand_link__3F8eK"); //清除所有品牌选项背景
		splicing_conditions_url(); /* 修改条件url */
	} else if (conditions_type == "price") {
		/* 价格条件 */
		selected_default_conditions($("#layout_content__hziOT"), 1);
		splicing_conditions_url(); /* 修改条件url */
	} else if (conditions_type == "level") {
		/* 级别条件 */
		selected_default_conditions($("#all_car_level"), 2);
		splicing_conditions_url(); /* 修改条件url */
	} else if (conditions_type == "points") {
		/* 懂车分条件 */
		selected_default_conditions($("#all_points"), 3);
		splicing_conditions_url(); /* 修改条件url */
	} else if (conditions_type == "energy") {
		/* 能源条件 */
		selected_default_conditions($("#all_energy"), 4);
		splicing_conditions_url(); /* 修改条件url */
	} else if (conditions_type == "different_countries") {
		/* 国别条件 */
		selected_default_conditions($("#all_different_countries"), 5);
		splicing_conditions_url(); /* 修改条件url */
	} else if (conditions_type == "seat_num") {
		/* 座位数条件 */
		selected_default_conditions($("#all_seat_num"), 6);
		splicing_conditions_url(); /* 修改条件url */
	}
	if ($(".filters_selected-list__3LDyn a").length == 0) {
		$("#all_conditions").hide();
		$("#tw-mt-32_series-collection_root__58y5u").show();
	}
}

/* 删除已选条件，选中'不限' */
function selected_default_conditions(elemenet, index) {
	/* 所有条件的父元素，条件集合的索引 */
	all_conditions[index] = null;
	$(elemenet).find("a").attr("class", "filters_item__3FqtJ"); //清除所有选项背景
	$(elemenet).find("a:eq(0)").attr("class", "filters_item__3FqtJ filters_selected__2JJnq"); //选中第一个(不限)
}

/* 重置条件 */
function reset_conditions() {
	/* 修改登录url */
	$(".to_login").attr("href",
		"http://127.0.0.1:8899/html/car_login.html?car_vehicle_selection");
	brand_name = ""; //品牌名称
	brand_name = ""; //品牌名称
	price = ""; //价格
	level = ""; //级别
	car_points = ""; //懂车分
	energy = ""; //能源
	different_countries = ""; //国别
	seat_num = ""; //座位数
	all_conditions[0] = null;
	$(".brand_brands__1VgjE a").attr("class", "brand_link__3F8eK"); //清除所有品牌选项背景
	selected_default_conditions($("#layout_content__hziOT"), 1); /* 价格条件 */
	selected_default_conditions($("#all_car_level"), 2); /* 级别条件 */
	selected_default_conditions($("#all_points"), 3); /* 懂车分条件 */
	selected_default_conditions($("#all_energy"), 4); /* 能源条件 */
	selected_default_conditions($("#all_different_countries"), 5); /* 国别条件 */
	selected_default_conditions($("#all_seat_num"), 6); /* 座位数条件 */
	/* 清除所有显示条件 */
	$(".filters_selected-list__3LDyn a").remove();
	$(".car-list_root__3bcdu li").remove();
	/* 没有条件 */
	$("#all_conditions").hide();
	$("#tw-mt-32_series-collection_root__58y5u").show();
	splicing_conditions_url(); /* 修改条件url */
}

/* 显示更多条件 */
function show_more_conditions(whether_show) {
	if (whether_show) {
		$("#more_conditions").show();
		$("#show_more_conditions span:eq(0)").hide();
		$("#show_more_conditions span:eq(1)").show();
	} else {
		$("#more_conditions").hide();
		$("#show_more_conditions span:eq(1)").hide();
		$("#show_more_conditions span:eq(0)").show();
	}
}

/* 切换品牌（不限/热门/A~Z） */
function switch_brand(conditions, element) {
	/* (条件，当前对象) */
	$(element).siblings("li").attr("class", "brand_letter__2mCmS");
	$(element).attr("class", "brand_letter__2mCmS brand_selected__3YcFo");
	if (conditions == "unlimited") {
		/* 不限：隐藏品牌列表 */
		load_leng = 1800;
		pageIndex = 1;
		brand_name = "";
		$(".car-list_root__3bcdu li").remove(); /* 清空车系/精美车图 */
		all_conditions[0] = null;
		flush_selected_conditions(); /* 刷新已选条件 */
		$(".brand_brands__1VgjE").parent().hide();
		$(".brand_brands__1VgjE a").attr("class", "brand_link__3F8eK"); //清除所有选项背景
		splicing_conditions_url();
		/* 品牌找车 */
		if ($("#brand_mess").css("display") == "block" && $("#switch_preferences a:eq(1)").attr("class") ==
			"jsx-2546748851 tw-inline-block tw-text-16 tw-leading-24 tw-text-common-black tw-mr-40 tw-relative xl:tw-text-18 xl:tw-leading-28 tw-font-semibold"
		) {
			$("#brand_mess").css("display", "none");
		}
	} else {
		/* 热门（popularity）/A~Z */
		$(".brand_brands__1VgjE").parent().show();
		load_popularity_brand(conditions);
	}
}

/* 往左查看历史浏览车系 */
function to_left_show() {
	$(".series-collection_navigation__vgYGq i:eq(0)").attr("onclick", "");
	$(".series-collection_navigation__vgYGq i:eq(0)").attr("class",
		"DCD_Icon icon_arrow_left_1 wrapped-swiper_circle__39IYv wrapped-swiper_button__35fg2 wrapped-swiper_disabled__37VHs"
	);
	$(".series-collection_navigation__vgYGq i:eq(1)").attr("onclick", "to_right_show()");
	$(".series-collection_navigation__vgYGq i:eq(1)").attr("class",
		"DCD_Icon icon_into_12 wrapped-swiper_circle__39IYv wrapped-swiper_button__35fg2");
	$(".swiper-wrapper").animate({
		"margin-left": "0px"
	}, 500);
}

/* 往右查看历史浏览车系 */
function to_right_show() {
	$(".series-collection_navigation__vgYGq i:eq(1)").attr("onclick", "");
	$(".series-collection_navigation__vgYGq i:eq(1)").attr("class",
		"DCD_Icon icon_into_12 wrapped-swiper_circle__39IYv wrapped-swiper_button__35fg2 wrapped-swiper_disabled__37VHs"
	);
	$(".series-collection_navigation__vgYGq i:eq(0)").attr("onclick", "to_left_show()");
	$(".series-collection_navigation__vgYGq i:eq(0)").attr("class",
		"DCD_Icon icon_arrow_left_1 wrapped-swiper_circle__39IYv wrapped-swiper_button__35fg2");
	$(".swiper-wrapper").animate({
		"margin-left": -(car_series_count * 306 - 1570) + "px"
	}, 500);
}

/* 拼接条件url */
function splicing_conditions_url() {
	/* 条件索引 */
	var conditions_url = "";
	for (var i = 0; i <= 6; i++) {
		conditions_url += all_conditions[i] != null && all_conditions[i] != "" ?
			all_conditions[i].conditions : "x";
		if (i != 6) conditions_url += "-";
	}
	conditions_url += "-" + pageIndex; //当前页数
	/* 精美车图 */
	if ($("#switch_preferences a:eq(2)").attr("class") ==
		"jsx-2546748851 tw-inline-block tw-text-16 tw-leading-24 tw-text-common-black tw-mr-40 tw-relative xl:tw-text-18 xl:tw-leading-28 tw-font-semibold"
	) {
		/* 查询精美车图 */
		select_all_series_images_by_conditions(conditions_url);
	} else {
		/* 查询指定条件车系 */
		select_all_series_by_conditions(conditions_url);
	}
}

/* 查询指定条件车系 */
function select_all_series_by_conditions(conditions_url) {
	var all_car_series_data = "";
	$.post("http://127.0.0.1:8899/api/consumer/Car_seriesController/vehicle_selection_by_conditions/" + conditions_url,
		function(data) {
			pages = data.pages;
			$(data.list).each(function(index, item) {
				all_car_series_data += "<li class=\"car-list_item__3nyEK\">" +
					"<div class=\"series-card_root__1ja7l car-list_card__1BJSa\">" +
					"<div style=\"display:inline-block;max-width:100%;overflow:hidden;position:relative;z-index:0\" " +
					"class=\"series-card_image__3g4j4\">" +
					"<div style=\"box-sizing:border-box;display:block;max-width:100%\"><img " +
					"style=\"max-width:100%;display:block;margin:0;border:none;padding:0\" " +
					"src=\"data:image/svg+xml;utf-8,&lt;svg width=&quot;166&quot; height=&quot;118&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot;/&gt;\" " +
					"aria-hidden=\"true\" role=\"presentation\" /></div><noscript><img " +
					"src=\"//p3.dcarimg.com/img/motor-img/f974dc4060ed75347ec712525d041b11~332x0.png\" " +
					"width=\"180px\" height=\"130px\" " +
					"style=\"position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;object-fit:cover\"/></noscript><img " +
					"src=\"http://120.48.47.144:8899/images/" + item.car_series_images_url_1 + "\" " +
					"width=\"180px\" height=\"130px\" " +
					"style=\"position:absolute;top:0;left:0;bottom:0;right:0;box-sizing:border-box;padding:0;border:none;margin:auto;display:block;width:0;height:0;min-width:100%;max-width:100%;min-height:100%;max-height:100%;object-fit:cover\" />" +
					"</div><a class=\"series-card_name__3QIlf\" href=\"http://127.0.0.1:8899/html/car_series_index.html?" +
					item.car_series_id + "\" target=\"_blank\" " +
					"rel=\"opener\">" + item.car_series_name + "</a>" +
					"<a class=\"series-card_score__2w2hO\" href=\"javascript:void(0)\" ><img " +
					"src=\"//lf3-motor.dcarstatic.com/obj/motor-fe-static/motor/pc/_next/./static/images/score-4f6b4186576fc452392c..svg\" " +
					"alt=\"懂车分\" height=\"16\">" +
					"<div class=\"jsx-690020249 series-card_star__1_lCm stars_stars-wrapper__zg7gU\" " +
					"style=\"--starWidth:12; --starHeight:12; --marginRight:0; --icon:url(\/\/lf3-motor\.dcarstatic\.com\/obj\/motor-fe-static\/motor\/pc\/_next\/\.\/static\/images\/star-highlight-6092d405945e3a2a3a5f\.\.png); --icon-vacant:url(\/\/lf3-motor\.dcarstatic\.com\/obj\/motor-fe-static\/motor\/pc\/_next\/\.\/static\/images\/star-normal-0d71d2c21de0ccf62fd0\.\.png);\">" +
					"<span class=\"jsx-690020249 stars_star__2uVtU\"></span><span " +
					"class=\"" + (item.car_points.car_points_avg > 1.5 ? 'jsx-690020249 stars_star__2uVtU' :
						'jsx-690020249 stars_star-vacant__Tfvup') + "\"></span><span " +
					"class=\"" + (item.car_points.car_points_avg > 2.5 ? 'jsx-690020249 stars_star__2uVtU' :
						'jsx-690020249 stars_star-vacant__Tfvup') + "\"></span><span " +
					"class=\"" + (item.car_points.car_points_avg > 3.5 ? 'jsx-690020249 stars_star__2uVtU' :
						'jsx-690020249 stars_star-vacant__Tfvup') + "\"></span><span " +
					"class=\"" + (item.car_points.car_points_avg > 4.5 ? 'jsx-690020249 stars_star__2uVtU' :
						'jsx-690020249 stars_star-vacant__Tfvup') + "\"></span></div>" + item.car_points
					.car_points_avg + "分" +
					"</a>" +
					"<p class=\"series-card_price__1Pwwb\" style=\"font-family:TEeTmQbk4q0XLGge\">" +
					item.min_manufacturer_price + "-" + item.max_manufacturer_price + "万" +
					"</p>" +
					"<div class=\"tw-relative car-selector_root__3b8GR series-card_count__3MQyn\">" +
					"共" + item.car_model_count +
					"款符合条件车型<i class=\"DCD_Icon icon_triangle_right\"></i></div>" +
					"<div class=\"series-card_button-group__2a953\"><a " +
					"class=\"series-card_button__JRZ5f series-card_primary__1ByNe\" " +
					"href=\"http://127.0.0.1:8899/html/car_purchase_calculation.html?" + item
					.car_series_id + "/0" + "\" " +
					"target=\"_blank\" rel=\"opener\">购车计算</a><a class=\"series-card_button__JRZ5f\" " +
					"href=\"http://127.0.0.1:8899/html/car_series_article.html?" + item
					.car_series_id +
					"\" target=\"_blank\" rel=\"opener\">资讯</a><a " +
					"class=\"series-card_button__JRZ5f\" href=\"http://127.0.0.1:8899/html/car_series_video.html?" +
					item
					.car_series_id + "\" " +
					"target=\"_blank\" rel=\"opener\">视频</a></div>" +
					"</div>" +
					"</li>";
			});
			$(".sort_count__32REk").text(data.total); // 总数量
			$(".car-list_root__3bcdu").append(all_car_series_data);
		}, "json");
}

/* 查询指定条件车系图片 */
function select_all_series_images_by_conditions(conditions_url) {
	var all_car_images_data = "";
	$.post("http://127.0.0.1:8899/api/consumer/Car_seriesController/select_all_series_images_by_conditions/" +
		conditions_url,
		function(data) {
			pages = data.pages;
			$(data.list).each(function(index, item) {
				all_car_images_data +=
					"<li class=\"car-list_item__3nyEK\"><div class=\"image_root__1eWQr car-list_card__1BJSa\"><a target=\"_blank\" href=\"http://127.0.0.1:8899/html/car_series_index.html?" +
					item.car_series_id +
					"\"><div class=\"image_image-wrapper__F-XKv\"> " +
					"<div class=\"image_image__2Tp58\" style=\"display: inline-block; max-width: 100%; overflow: hidden; position: relative; z-index: 0;\"> " +
					"<div style=\"box-sizing: border-box; display: block; max-width: 100%;\"> " +
					"<img src=\"data:image/svg+xml;utf-8,<svg width=&quot;249&quot; height=&quot;166&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot;/>\" aria-hidden=\"true\"  " +
					"role=\"presentation\" style=\"max-width: 100%; display: block; margin: 0px; border: none; padding: 0px;\"></div><img src=\"http://120.48.47.144:8899/images/" +
					item.car_series_images_url_1 + "\" " +
					"width=\"249\" height=\"166\" style=\"position: absolute; inset: 0px; box-sizing: border-box; padding: 0px; border: none; margin: auto; display: block; width: 0px; height: 0px; min-width: 100%;  " +
					"max-width: 100%; min-height: 100%; max-height: 100%; object-fit: cover;\"></div><a href=\"http://127.0.0.1:8899/html/car_actual_large_picture.html?0/"+item.car_series_id+"/0/0\" target=\"_blank\"><span class=\"image_count__z9YJs\">共" +
					item.car_series_images_count +
					"张图<i class=\"DCD_Icon icon_into_12\"></i></span></a></div> " +
					"<div class=\"image_info__2a0sm\"><p class=\"image_main__2qNfG\"> " +
					"<strong class=\"image_name__2s0R-\">" + item.car_series_name +
					"</strong><span class=\"image_price__1xCk_\" style=\"font-family: TEeTmQbk4q0XLGge;\">" +
					item.min_manufacturer_price + "-" + item.max_manufacturer_price +
					"万</span></p></div></div></a></li>";
			});
			$(".sort_count__32REk").text(data.total); //总数量
			$(".car-list_root__3bcdu").append(all_car_images_data);
		}, "json");
}

/* 切换首选项(选新车，品牌找车，精美车图)*/
function switch_preferences(type, index) {
	$(".car-list_root__3bcdu li").remove(); /* 清空车系/精美车图 */
	$("#switch_preferences span").remove();
	$("#switch_preferences a:eq(" + index + ")").append(
		"<span class=\"tw-w-24 tw-h-4 tw-bg-common-yellow tw-absolute tw-top-full tw-left-1/2 tw--ml-12 tw-mt-8\"></span>"
	);
	$("#switch_preferences a:eq(" + index + ")").attr("class",
		"jsx-2546748851 tw-inline-block tw-text-16 tw-leading-24 tw-text-common-black tw-mr-40 tw-relative xl:tw-text-18 xl:tw-leading-28 tw-font-semibold"
	);
	$("#switch_preferences a:eq(" + index + ")").siblings("a").attr("class",
		"jsx-2546748851 tw-inline-block tw-text-16 tw-leading-24 tw-text-common-black tw-mr-40 tw-relative xl:tw-text-18 xl:tw-leading-28"
	);
	$("#brand_mess").hide();
	$("#other_conditions").show();
	switch_brand('popularity', $(".brand_letters__1BZHM li:eq(1)")); /* 重置为热门 */
	if (type == "brand_find_car") {
		$("#other_conditions").hide();
	}
	load_leng = 1800;
	pageIndex = 1;
	reset_conditions(); /* 重置全部条件 */
}

/* 切换浏览历史/我的关注 */
function switch_history_follow(type) {
	/* 清空左右翻动按钮属性 */
	$(".series-collection_navigation__vgYGq i:eq(0)").attr("onclick", "");
	$(".series-collection_navigation__vgYGq i:eq(0)").attr("class",
		"DCD_Icon icon_arrow_left_1 wrapped-swiper_circle__39IYv wrapped-swiper_button__35fg2 wrapped-swiper_disabled__37VHs"
	);
	$(".series-collection_navigation__vgYGq i:eq(1)").attr("onclick", "to_right_show()");
	$(".series-collection_navigation__vgYGq i:eq(1)").attr("class",
		"DCD_Icon icon_into_12 wrapped-swiper_circle__39IYv wrapped-swiper_button__35fg2");
	$(".swiper-wrapper div").remove();
	$(".swiper-wrapper").css("margin-left", "0px");
	$(".series-collection_navigation__vgYGq").hide(); //隐藏翻动按钮
	if (type == "history") { //浏览历史
		$("#my_follow").attr("class", "series-collection_type-item__1Bkxj");
		$("#history_browsing").attr("class",
			"series-collection_type-item__1Bkxj series-collection_active__3-tAO");
		select_history_browsing_car_series();
	} else { //我的关注
		$("#history_browsing").attr("class", "series-collection_type-item__1Bkxj");
		$("#my_follow").attr("class", "series-collection_type-item__1Bkxj series-collection_active__3-tAO");
		select_my_follow();
	}
}

/* 懒加载刷新页面 */
window.onscroll = function() {
	var scroll_top = document.body.scrollTop || document.documentElement.scrollTop;
	var win_top = window.innerHeight;
	if (scroll_top + win_top > load_leng && pageIndex != pages) {
		pageIndex++;
		splicing_conditions_url();
		load_leng += 1200;
	}
}
